const a = { start: 3, end: 5 };
const b = { start: 7, end: 8 };
const c = { start: 4, end: 6 };

function isOverlapped (first, second) {
  const {start : f_start, end: f_end} = first
  const {start : s_start, end: s_end} = second
  if (f_start > s_end || f_end < s_start) { // 这种情况下是不相交的
    return false
  }
  return true
}
console.log(isOverlapped(c, a))

function merge (intervals) {
  intervals.sort((a, b) => a.start - b.start)
  for (let x = 0; x < intervals.length; x++) {
    const next = intervals[x + 1]
    const current = intervals[x]
    if (next) {
      if(isOverlapped(current, next)) {
        const start = current.start
        const end = Math.max(current.end, next.end)
        intervals.splice(x + 1, 1)
        intervals.splice(x, 1, {start, end})
      }
    }
  }
  return intervals
}

console.log(merge([
 a,
 b,
 c
]))